From 205a50dc8814f88551f44b6076a4940866cb60ff Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Wed, 5 Apr 2017 20:50:22 +0200 Subject: [PATCH] AllKinds tests: cargo-bench, cargo-build --- tests/bench.rs | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/build.rs | 48 +++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+) diff --git a/tests/bench.rs b/tests/bench.rs index fdb16f370..a03fe512a 100644 --- a/tests/bench.rs +++ b/tests/bench.rs @@ -53,6 +53,88 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured ")); } +#[test] +fn bench_bench_implicit() { + if !is_nightly() { return } + + let prj = project("foo") + .file("Cargo.toml" , r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + "#) + .file("src/main.rs", r#" + #![feature(test)] + extern crate test; + #[bench] fn run1(_ben: &mut test::Bencher) { } + fn main() { println!("Hello main!"); }"#) + .file("tests/other.rs", r#" + #![feature(test)] + extern crate test; + #[bench] fn run3(_ben: &mut test::Bencher) { }"#) + .file("benches/mybench.rs", r#" + #![feature(test)] + extern crate test; + #[bench] fn run2(_ben: &mut test::Bencher) { }"#); + + assert_that(prj.cargo_process("bench").arg("--benches"), + execs().with_status(0) + .with_stderr(format!("\ +[COMPILING] foo v0.0.1 ({dir}) +[FINISHED] release [optimized] target(s) in [..] +[RUNNING] target[/]release[/]deps[/]mybench-[..][EXE] +", dir = prj.url())) + .with_stdout(" +running 1 test +test run2 ... bench: [..] 0 ns/iter (+/- 0) + +test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured + +")); +} + +#[test] +fn bench_bin_implicit() { + if !is_nightly() { return } + + let prj = project("foo") + .file("Cargo.toml" , r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + "#) + .file("src/main.rs", r#" + #![feature(test)] + extern crate test; + #[bench] fn run1(_ben: &mut test::Bencher) { } + fn main() { println!("Hello main!"); }"#) + .file("tests/other.rs", r#" + #![feature(test)] + extern crate test; + #[bench] fn run3(_ben: &mut test::Bencher) { }"#) + .file("benches/mybench.rs", r#" + #![feature(test)] + extern crate test; + #[bench] fn run2(_ben: &mut test::Bencher) { }"#); + + assert_that(prj.cargo_process("bench").arg("--bins"), + execs().with_status(0) + .with_stderr(format!("\ +[COMPILING] foo v0.0.1 ({dir}) +[FINISHED] release [optimized] target(s) in [..] +[RUNNING] target[/]release[/]deps[/]foo-[..][EXE] +", dir = prj.url())) + .with_stdout(" +running 1 test +test run1 ... bench: [..] 0 ns/iter (+/- 0) + +test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured + +")); +} + #[test] fn bench_tarname() { if !is_nightly() { return } diff --git a/tests/build.rs b/tests/build.rs index 1eea86b5c..325d0e81c 100644 --- a/tests/build.rs +++ b/tests/build.rs @@ -2215,6 +2215,54 @@ fn filtering() { assert_that(&p.bin("examples/b"), is_not(existing_file())); } +#[test] +fn filtering_implicit_bins() { + let p = project("foo") + .file("Cargo.toml", r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + "#) + .file("src/lib.rs", "") + .file("src/bin/a.rs", "fn main() {}") + .file("src/bin/b.rs", "fn main() {}") + .file("examples/a.rs", "fn main() {}") + .file("examples/b.rs", "fn main() {}"); + p.build(); + + assert_that(p.cargo("build").arg("--bins"), + execs().with_status(0)); + assert_that(&p.bin("a"), existing_file()); + assert_that(&p.bin("b"), existing_file()); + assert_that(&p.bin("examples/a"), is_not(existing_file())); + assert_that(&p.bin("examples/b"), is_not(existing_file())); +} + +#[test] +fn filtering_implicit_examples() { + let p = project("foo") + .file("Cargo.toml", r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + "#) + .file("src/lib.rs", "") + .file("src/bin/a.rs", "fn main() {}") + .file("src/bin/b.rs", "fn main() {}") + .file("examples/a.rs", "fn main() {}") + .file("examples/b.rs", "fn main() {}"); + p.build(); + + assert_that(p.cargo("build").arg("--examples"), + execs().with_status(0)); + assert_that(&p.bin("a"), is_not(existing_file())); + assert_that(&p.bin("b"), is_not(existing_file())); + assert_that(&p.bin("examples/a"), existing_file()); + assert_that(&p.bin("examples/b"), existing_file()); +} + #[test] fn ignore_dotfile() { let p = project("foo") -- 2.30.2